import request from '@/utils/request'

// =============================================================================
// 客户画像分类 API (CRMCustomerProfileCategory)
// =============================================================================

export function GetCRMCustomerProfileCategory(id, args) {
  return request({
    url: `/crm/api/crmcustomerprofilecategory/${id || ''}${args && ('?' + args) || ''}`,
    method: 'get'
  })
}

export function PostCRMCustomerProfileCategory(data) {
  return request({
    url: '/crm/api/crmcustomerprofilecategory/',
    headers: { 'content-type': 'application/json' },
    method: 'post',
    data: data
  })
}

export function PutCRMCustomerProfileCategory(id, data) {
  return request({
    url: `/crm/api/crmcustomerprofilecategory/${id || ''}`,
    headers: { 'content-type': 'application/json' },
    method: 'put',
    data: JSON.stringify(data)
  })
}

export function DeleteCRMCustomerProfileCategory(id) {
  return request({
    url: `/crm/api/crmcustomerprofilecategory/${id || ''}`,
    method: 'delete'
  })
}

// =============================================================================
// 客户画像参数 API (CRMCustomerProfileParameter)
// =============================================================================

export function GetCRMCustomerProfileParameter(id, args) {
  return request({
    url: `/crm/api/crmcustomerprofileparameter/${id || ''}${args && ('?' + args) || ''}`,
    method: 'get'
  })
}

export function PostCRMCustomerProfileParameter(data) {
  return request({
    url: '/crm/api/crmcustomerprofileparameter/',
    headers: { 'content-type': 'application/json' },
    method: 'post',
    data: data
  })
}

export function PutCRMCustomerProfileParameter(id, data) {
  return request({
    url: `/crm/api/crmcustomerprofileparameter/${id || ''}`,
    headers: { 'content-type': 'application/json' },
    method: 'put',
    data: JSON.stringify(data)
  })
}

export function DeleteCRMCustomerProfileParameter(id) {
  return request({
    url: `/crm/api/crmcustomerprofileparameter/${id || ''}`,
    method: 'delete'
  })
}

// =============================================================================
// 客户画像实例 API (CRMCustomerProfile)
// =============================================================================

export function GetCRMCustomerProfile(id, args) {
  return request({
    url: `/crm/api/crmcustomerprofile/${id || ''}${args && ('?' + args) || ''}`,
    method: 'get'
  })
}

export function PostCRMCustomerProfile(data) {
  return request({
    url: '/crm/api/crmcustomerprofile/',
    headers: { 'content-type': 'application/json' },
    method: 'post',
    data: data
  })
}

export function PutCRMCustomerProfile(id, data) {
  return request({
    url: `/crm/api/crmcustomerprofile/${id || ''}`,
    headers: { 'content-type': 'application/json' },
    method: 'put',
    data: data
  })
}

export function DeleteCRMCustomerProfile(id) {
  return request({
    url: `/crm/api/crmcustomerprofile/${id || ''}`,
    method: 'delete'
  })
}

// =============================================================================
// 特殊方法 - 获取客户完整画像
// =============================================================================

/**
 * 获取指定客户的完整画像数据
 * @param {number} customerId 客户ID
 * @returns {Promise} 包含分类统计和画像数据的Promise
 */
export function GetCustomerCompleteProfile(customerId) {
  return request({
    url: `/crm/api/crmcustomerprofile/?customer_id=${customerId}&action=complete_profile`,
    method: 'get'
  })
}

/**
 * 批量验证客户画像参数
 * @param {Array} profileIds 画像实例ID数组
 * @returns {Promise}
 */
export function BatchVerifyCustomerProfile(profileIds) {
  return request({
    url: '/crm/api/crmcustomerprofile/',
    headers: { 'content-type': 'application/json' },
    method: 'post',
    data: {
      action: 'batch_verify',
      profile_ids: profileIds
    }
  })
}

/**
 * 根据分类获取参数列表
 * @param {number} categoryId 分类ID
 * @returns {Promise}
 */
export function GetParametersByCategory(categoryId) {
  return request({
    url: `/crm/api/crmcustomerprofileparameter/?category_id=${categoryId}`,
    method: 'get'
  })
}
